import {
  getProjectReportList,
  getCusDocsList,
  getTotalPackageList,
  getEngineerAgentList,
  getDoorFactoryList,
  addProjectReport,
  updateProjectReport,
  getLockModel,
  getCompetitivebrand,
  getProjectStatusList,
  uploadFile,
  projectServeyUpdate,
  projectServeyQuery
} from "@/api/projectReport";

function getDetail() {
  let detail = {};
  try {
    detail = JSON.parse(sessionStorage.getItem("projectReportDetail"));
  } catch (error) {
    return undefined;
  }
  return detail;
}

const state = {
  projectReportDetail: getDetail() || {},
  pageIndex: 1
};
const actions = {
  getProjectReportList({}, payload) {
    return new Promise((resolve, reject) => {
      getProjectReportList(payload)
        .then(res => {
          resolve(res);
        })
        .catch(err => {
          reject(err);
        });
    });
  },
  getCusDocsList({}, payload) {
    return new Promise((resolve, reject) => {
      getCusDocsList(payload)
        .then(res => {
          resolve(res);
        })
        .catch(err => {
          reject(err);
        });
    });
  },
  getTotalPackageList({}, payload) {
    return new Promise((resolve, reject) => {
      getTotalPackageList(payload)
        .then(res => {
          resolve(res);
        })
        .catch(err => {
          reject(err);
        });
    });
  },
  getEngineerAgentList({}, payload) {
    return new Promise((resolve, reject) => {
      getEngineerAgentList(payload)
        .then(res => {
          resolve(res);
        })
        .catch(err => {
          reject(err);
        });
    });
  },
  getDoorFactoryList({}, payload) {
    return new Promise((resolve, reject) => {
      getDoorFactoryList(payload)
        .then(res => {
          resolve(res);
        })
        .catch(err => {
          reject(err);
        });
    });
  },
  addProjectReport({}, payload) {
    return new Promise((resolve, reject) => {
      addProjectReport(payload)
        .then(res => {
          resolve(res);
        })
        .catch(err => {
          reject(err);
        });
    });
  },
  updateProjectReport({}, payload) {
    return new Promise((resolve, reject) => {
      updateProjectReport(payload)
        .then(res => {
          resolve(res);
        })
        .catch(err => {
          reject(err);
        });
    });
  },
  getLockModel({}, payload) {
    return new Promise((resolve, reject) => {
      getLockModel(payload)
        .then(res => {
          resolve(res);
        })
        .catch(err => {
          reject(err);
        });
    });
  },
  getCompetitivebrand({}, payload) {
    return new Promise((resolve, reject) => {
      getCompetitivebrand(payload)
        .then(res => {
          resolve(res);
        })
        .catch(err => {
          reject(err);
        });
    });
  },
  getProjectStatusList({}, payload) {
    return new Promise((resolve, reject) => {
      getProjectStatusList(payload)
        .then(res => {
          resolve(res);
        })
        .catch(err => {
          reject(err);
        });
    });
  },
  uploadFile({}, payload) {
    return new Promise((resolve, reject) => {
      uploadFile(payload)
        .then(res => {
          resolve(res);
        })
        .catch(err => {
          reject(err);
        });
    });
  },
  projectServeyUpdate({}, payload) {
    return new Promise((resolve, reject) => {
      projectServeyUpdate(payload)
        .then(res => {
          resolve(res);
        })
        .catch(err => {
          reject(err);
        });
    });
  },
  projectServeyQuery({}, payload) {
    return new Promise((resolve, reject) => {
      projectServeyQuery(payload)
        .then(res => {
          resolve(res);
        })
        .catch(err => {
          reject(err);
        });
    });
  }
};
const mutations = {
  setDocsDetail(state, payload) {
    sessionStorage.setItem("projectReportDetail", JSON.stringify(payload));
    state.projectReportDetail = payload;
  },
  resetDocsDetail(state, payload) {
    sessionStorage.removeItem("projectReportDetail");
    state.projectReportDetail = {};
  },
  setPageIndex(state, payload) {
    state.pageIndex = payload;
  }
};
const getters = {};
export default {
  namespaced: true,
  state,
  actions,
  mutations,
  getters
};
